//
//  MyIncomeViewController.m
//  SelfDriving
//
//  Created by apple on 16/1/15.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "MyIncomeViewController.h"
#import "BusinessService+User.h"
#import "ShareStatisticsViewController.h"
#import "KuaiPaiFenXiVC.h"
#import "XhwDynamicAnalyzeCtrl.h"
@interface MyIncomeViewController ()<UITableViewDelegate,UITableViewDataSource,UIWebViewDelegate,BaseTableDetelage>
@property (weak, nonatomic) IBOutlet BaseTable *table;

@end

@implementation MyIncomeViewController
{
    LoginResponseModel *user;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _table.bdelegate = self;
    [self initData:0];
 
}

-(void)scollTop:(NSNotification *)not{
    [_table scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBarHidden = NO;
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(scollTop:)
     name:@"scollTop"
     object:nil];
}
-(void)initData:(int)index{
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [[BusinessService shareInstance]getincome:dic success:^(id result) {
        user = result;
        [_table reloadData];
    } failure:^(id result) {
        
    }];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else if (section == 1){
        return 1;
    }else if (section == 2){
//        return 4;
        return 3;//不要未领取收益
    }else{
        return 7;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 2){
        return 30;
    }
    return 8;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 120;
    }
    return 45;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 2) {
        UIButton *btn  = [[UIButton alloc]initWithFrame:CGRectMake(0, 0,SCRE_WIDTH, 30)];
        [btn setTitle:@"如何领取我的收益？立即了解" forState:UIControlStateNormal];
        [btn setTitleColor:colorGrey forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:13];
        btn.backgroundColor = colorBG;
        [btn addTarget:self action:@selector(toshouyi:) forControlEvents:UIControlEventTouchUpInside];
        return btn;
    }
    return nil;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    if (indexPath.section == 0) {
        UIImageView *imgbg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCRE_WIDTH+100, 120)];
        imgbg.image = [UIImage imageNamed:@"stbg"];
        [cell.contentView addSubview:imgbg];
        
        UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 30, SCRE_WIDTH, 30)];
        lable.text = @"总收益(元)";
        lable.textColor = [UIColor whiteColor];
        lable.font = [UIFont systemFontOfSize:13];
        lable.textAlignment = NSTextAlignmentCenter;
        [cell.contentView addSubview:lable];
        
        UILabel *monery = [[UILabel alloc]initWithFrame:CGRectMake(0, 60, SCRE_WIDTH, 30)];
//        monery.text = [ValidateHelper numberFormat:[NSString stringWithFormat:@"%d",[user.total_income intValue]]];
        monery.text = [NSString stringWithFormat:@"%@",user.total_income];

        monery.textColor = [UIColor whiteColor];
        monery.font = [UIFont systemFontOfSize:16];
        monery.textAlignment = NSTextAlignmentCenter;
        [cell.contentView addSubview:monery];
        return cell;
     }
    if (indexPath.section == 1) {
        cell.textLabel.text = @"当前余额";
//        cell.detailTextLabel.text = [ValidateHelper numberFormat:[NSString stringWithFormat:@"%@",user.money]];
        cell.detailTextLabel.text = user.money;
    }
    if (indexPath.section == 2) {
        if (indexPath.row == 0) {
            cell.textLabel.text = @"今日收益";
//            cell.detailTextLabel.text = [ValidateHelper numberFormat:[NSString stringWithFormat:@"%f",user.today_income]];
            
            cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",user.today_income];
        }
        if (indexPath.row == 1) {
            //xhw2018-1-11改bug15052
            cell.textLabel.text = @"当月收益";
//            cell.detailTextLabel.text = [ValidateHelper numberFormat:[NSString stringWithFormat:@"%f",user.month_income]];
            cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",user.month_income];
        }
//        if (indexPath.row == 2) {
//            cell.textLabel.text = @"未领收益";
////            cell.detailTextLabel.text = [ValidateHelper numberFormat:[NSString stringWithFormat:@"%f",user.unget_income]];
//            cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",user.unget_income];
//        }
//        if (indexPath.row == 3)
        if (indexPath.row == 2)

        {
            cell.textLabel.text = @"近期收益排名";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
    }
    if(indexPath.section == 3){
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        if (indexPath.row == 0) {
            cell.textLabel.text = @"分享统计";
        }
        if (indexPath.row == 1) {
            cell.textLabel.text = @"动态统计";
        }
        if (indexPath.row == 2) {
            cell.textLabel.text = @"快拍统计";
        }
        if (indexPath.row == 3) {
            cell.textLabel.text = @"有奖打卡";
        }
        if (indexPath.row == 4) {
            cell.textLabel.text = @"举报统计";
        }
        if (indexPath.row == 5) {
            cell.textLabel.text = @"账户资料";
        }
        if (indexPath.row == 6) {
            cell.textLabel.text = @"红包及发款记录";
        }
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if(indexPath.section == 2){
//        if (indexPath.row == 3)
        if (indexPath.row == 2)  //xhw2018-2-11
        {
            UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"GR"
                                                                         bundle:[NSBundle mainBundle]];
            UIViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"RankingVC"];
            [self.navigationController pushViewController:searchResultDetailController animated:YES];
        }
    }
    if(indexPath.section == 3){
        if (indexPath.row == 0) {
            UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"GR"
                                                                         bundle:[NSBundle mainBundle]];
            ShareStatisticsViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"ShareStatisticsVC"];
            searchResultDetailController.type = @"分享统计";
            [self.navigationController pushViewController:searchResultDetailController animated:YES];
        }
        if (indexPath.row == 1) {
//            UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"GR"
//                                                                         bundle:[NSBundle mainBundle]];
//            UIViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"DynamicAnalysisVC"];
//            [self.navigationController pushViewController:searchResultDetailController animated:YES];
            //xhw2018-1-18改:
            UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"GR"
                                                                         bundle:[NSBundle mainBundle]];
            XhwDynamicAnalyzeCtrl *vc = [customerStoryboard instantiateViewControllerWithIdentifier:@"XhwDynamicAnalyzeCtrl"];
            vc.title = @"动态分析";
            [self.navigationController pushViewController:vc animated:YES];
        }
        //xhw2017-1-17改bug15050:点击快拍统计界面无响应
        if (indexPath.row == 2) {
            UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"GR"
                                                                         bundle:[NSBundle mainBundle]];
            KuaiPaiFenXiVC *vc = [customerStoryboard instantiateViewControllerWithIdentifier:@"KuaiPaiFenXiVC"];
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (indexPath.row == 3) {
            UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"GR"
                                                                         bundle:[NSBundle mainBundle]];
            ShareStatisticsViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"ShareStatisticsVC"];
            searchResultDetailController.type = @"有奖打卡";
            [self.navigationController pushViewController:searchResultDetailController animated:YES];
        }
        if (indexPath.row == 4) {
            UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"GR"
                                                                         bundle:[NSBundle mainBundle]];
            ShareStatisticsViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"ShareStatisticsVC"];
            searchResultDetailController.type = @"举报统计";
            [self.navigationController pushViewController:searchResultDetailController animated:YES];
        }
        if (indexPath.row == 5) {
            UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"GR"
                                                                         bundle:[NSBundle mainBundle]];
            UIViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"AccountInformationVC"];
            [self.navigationController pushViewController:searchResultDetailController animated:YES];
        }
        if (indexPath.row == 6) {
            UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"GR"
                                                                         bundle:[NSBundle mainBundle]];
            UIViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"HongBaoViewController"];
            [self.navigationController pushViewController:searchResultDetailController animated:YES];
        }
        
        
    }
}
-(void)toshouyi:(UIButton *)btn{
    UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"FJ"
                                                                 bundle:[NSBundle mainBundle]];
    WebViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"WebVC"];
    searchResultDetailController.titlename = @"分润收益";
    searchResultDetailController.Url = shouyiurl;
    [self.navigationController pushViewController:searchResultDetailController animated:YES];

}

-(void)webViewDidFinishLoad:(UIWebView *)webView{
    
//    NSString *tete = [NSString stringWithFormat:@"show(\"%@\",\"%@\");",xy,@"参与人数"];
//    [webView stringByEvaluatingJavaScriptFromString:tete];
    
}

- (IBAction)backActino:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
